<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <script src="./js/earthsdk.js"></script>
    <!-- 自定义Css样式 -->
    <link rel="stylesheet" href="./css/example1.css">
    <title>拾取对象pick</title>
    <style>
        html,
        body,
        #app {
            width: 100%;
            height: 100%;
            margin: 0px;
            padding: 0px;
        }

        #box>p {
            text-align: left;
        }

        #box>p:nth-child(1)>span {
            color: sandybrown;
        }
    </style>
</head>

<body>
    <div id="app"></div>
    <div id="panel">
        <div id="box">
            <p><span>提示：</span>支持响应如下鼠标操作</p>
            <p>【控制台查看信息】</p>
            <p>鼠标左键点击leftClick</p>
            <p>鼠标左键点击rightClick</p>
            <p>鼠标进入mouseEnter</p>
            <p>鼠标移出mouseLeave</p>
        </div>
    </div>
    <script>
        /** ---------------------------------地球创建------------------------------------**/
        // Vue中引入方式：import { ESObjectsManager } from 'earthsdk3';
        const { ESObjectsManager } = window['EarthSDK3']
        const { ESCesiumViewer } = window['EarthSDK3_Cesium']
        const { ESUeViewer } = window['EarthSDK3_UE']

        const objm = new ESObjectsManager(ESCesiumViewer, ESUeViewer);
        window.g_objm = objm;

        // 创建Cesium视口
        const viewer = objm.createCesiumViewer({
            type: 'ESCesiumViewer',
            container: document.getElementById("app"),
        });

        // 通过json创建一个影像图层
        const imageryLayer = objm.createSceneObjectFromJson({
            "id": "9812a65f-0de0-4f7b-b234-809c0c2fb8ef",
            "type": "ESImageryLayer",
            "maximumLevel": 16,
            "url": "https://server.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"
        });

        // 创建一个ESImageLabel对象,该对象拥有特殊鼠标事件widgetEvent
        /**
         * widgetEvent:鼠标事件
         *  返回信息:
         *      左键点击:{event:"leftClick"}
         *      右键点击:{event:"rightClick"}
         *      鼠标进入:{event:"mouseEnter"}
         *      鼠标移出:{event:"mouseLeave"}
        */
        const { ESImageLabel } = window['EarthSDK3']
        const sceneObj = objm.createSceneObject(ESImageLabel)
        sceneObj.position = [116.404, 39.904, 0]
        // 监听widgetEvent事件
        sceneObj.allowPicking = true//允许被拾取
        sceneObj.widgetEvent.don((e) => {
            console.log("widgetEvent信息", e)
            switch (e.type) {
                case 'mouseEnter':
                    // alert("鼠标进入!")
                    break;
                case 'mouseLeave':
                    // alert("鼠标移出!")
                    break;
                case 'leftClick':
                    alert("被左键点击了!")
                    break;
                case 'rightClick':
                    alert("被右键点击了!")
                    break;
                default:
                    break;
            }

        })
        setTimeout(() => {
            sceneObj.flyTo()
        }, 2000)



    </script>

    <!-- 切换UE和Cesium引擎的组件（Vue） -->
    <div id="root">
        <switch-engine :objm="objm"></switch-engine>
    </div>
    <!-- Vue文件 -->
    <script src="./js/vue.global.js"></script>
    <!-- 切换UE和Cesium的组件 -->
    <script src="./js/switchEngineCom.js"></script>
</body>

</html>